package com.chenshanji.lease.web.admin.controller.apartment;

import com.chenshanji.lease.common.result.Result;
import com.chenshanji.lease.web.admin.service.FileService;
import com.obs.services.exception.ObsException;
import com.sun.jdi.InternalException;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.ErrorResponseException;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.rmi.ServerException;

@Tag(name = "文件管理")
@RequestMapping("/admin/file")
@RestController
public class FileUploadController {

    @Autowired
    private FileService service;

    @PostMapping("upload")
    @Operation(summary = "上传文件",
            description = "上传文件到华为OBS，支持图片格式（如 JPG、PNG），文件大小不能超过 5MB。")
    public Result<String> upload(@RequestParam MultipartFile file) throws ServerException, ErrorResponseException, IOException, InternalException, ObsException {
        String url = service.upload(file);
        return Result.ok(url);
    }
}
